home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DOS.SWG / 0008_Kill DIR Routine.pas < prev    next >
Pascal/Delphi Source File  |  1993-06-08  |  2KB  |  53 lines

  1. (*
  2. ===========================================================================
  3.  BBS: The Beta Connection
  4. Date: 06-05-93 (12:54)             Number: 67
  5. From: BRENDEN WALKER               Refer#: NONE
  6.   To: WAYNE DOYLE                   Recvd: NO
  7. Subj: DIR. SEARCH                    Conf: (321) Pascal___U
  8. ---------------------------------------------------------------------------
  9.  WD│ Hi Everyone,
  10.    │     I'm interested in finding out how to have the computer search and
  11.    │ find all of the available directories on a disk.  I have a program which
  12.    │ deletes all of *.BAK files on a disk and I'd like to know how it finds
  13.    │ all of the directories.
  14.  
  15.   The below example code, will kill a directory and all of it's
  16. sub-directories.  This could be modified to delete all of the .BAK files in
  17. all directories on the hard-drive.
  18.  
  19.   Of course, this may not help much, but I rarely use pseudo-code.
  20. *)
  21.  
  22. procedure Kill_Dir(p : pathstr);
  23. var Od, Rd : pathstr;
  24.     Sr : SearchRec;
  25.     t : file;
  26.  
  27. begin
  28.   getdir(0,Od);
  29.   ChDir(p);
  30.   if length(p) > 4 then p := p + '\';
  31.   FindFirst('*.*', anyfile, Sr);
  32.   while DosError = 0 do
  33.   begin
  34.     temp := p + Sr.Name;
  35.     if (Sr.Attr and Directory > 0) then
  36.     begin
  37.        if (Sr.Name <> '.') and (Sr.Name <> '..') then
  38.        begin
  39.          Rd := temp;
  40.          Kill_Dir(temp);
  41.          RmDir(Rd);
  42.        end;
  43.     end
  44.       else
  45.       begin
  46.         assign(t,sr.name);
  47.         erase(t);
  48.       end;
  49.     FindNext(Sr);
  50.   end;
  51.   ChDir(Od);
  52. end;
  53.